﻿using APS_Define_W32;
using APS168_W64;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace PerpheralDevice.AdLink {
    /// <summary>
    /// 凌华板卡对象容器
    /// </summary>
    public class APS168x64CardContainer : AppFramework.DesignMode.Singleton<APS168x64CardContainer> {

        private int mfBoardIDInBits = 0;
        private APS168x64CardContainer() { }

        public IEnumerable<int> CardIDList {
            get {
                List<int> retList = new ();
                for (int i = 0; i < 16; i++) {
                    if (((this.mfBoardIDInBits >> i) & 1) == 1) {
                        retList.Add(i);
                    }
                }
                return retList;
            }
        }

        public int GetCardName(int cardID) {
            if (APS168.APS_initial(ref mfBoardIDInBits, 0) != 0) {
                throw new AppTException<APS168x64CardContainer>($"凌华板卡对象容器构造失败");
            }
            if (!this.CardIDList.Contains(cardID)) {
                throw new AppTException<APS168x64CardContainer>($"没有找到对应的凌华板卡，板卡ID:{cardID}");
            }

            int retCardName = 0;
            _ = APS168.APS_get_card_name(cardID, ref retCardName);
            return retCardName;
        }

    }
}
